//
//  MainViewController.swift
//  SinaWeibo23
//
//  Created by apple on 16/1/30.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

 
    let mainTabbar = MainTabbar()
    
    
   
    @objc private func plusBtnDidClick() {
        print(__FUNCTION__)
    }
    
    
   
    override func viewDidLoad() {
        super.viewDidLoad()
     
        print(tabBar.classForCoder)
        
      
        setValue(mainTabbar, forKey: "tabBar")
        let actionName = "plusBtnDidClick"
     
        mainTabbar.plusBtn.addTarget(self, action: Selector(actionName), forControlEvents: .TouchUpInside)
        print(tabBar.classForCoder)
       
        addChildViewControllers()
    }
    
    
    private func addChildViewControllers() {
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    }
    
    //MARK: 添加单个视图控制器
    private func addChildViewController(vc: UIViewController, title: String,imageName: String) {
        //设置渲染颜色
        tabBar.tintColor = UIColor.orangeColor()
        let nav = UINavigationController(rootViewController: vc)
        vc.title = title
//        vc.tabBarItem.title  = "首页"
//        vc.navigationItem.title = "哈哈哈"
        
        //设置tabbaritem的图片
        vc.tabBarItem.image = UIImage(named: imageName)
        addChildViewController(nav)
    }
    
    

}
